<?php

namespace App\Jobs;

use App\Models\UserLog;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class OperationLogJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    // 任务可以尝试的最大次数。
    public $tries = 2;

    // 任务可以执行的最大秒数 (超时时间)。
    public $timeout = 120;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        //
        $this->queue = 'accountLog';
        $this->data = $data;
    }

    private $data;

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        UserLog::create($this->data);
        Log::channel('joblog')->info('--------------------------请求日志队列开始--------------------------');
        Log::channel('joblog')->info('队列名称:'.$this->queue);
        Log::channel('joblog')->info('请求地址:'.$this->data['path']);
        Log::channel('joblog')->info('请求方式:'.$this->data['method']);
        Log::channel('joblog')->info('请求参数:'.json_encode($this->data ,JSON_UNESCAPED_UNICODE));
        Log::channel('joblog')->info('--------------------------请求日志队列结束--------------------------');
    }
}
